<?php
declare (strict_types = 1);

namespace app\adminapi\controller\system\setting;

use adminmatrix\admin\BaseController;
use adminmatrix\admin\service\JsonService;
use app\adminapi\logic\system\setting\DatabaseLogic;
use think\Request;
use think\response\Json;

class DatabaseController extends BaseController
{


    public function tableField(Request $request , DatabaseLogic $database) : Json
    {
        try {
            $lists = $database->getField($request);
            return  JsonService::success('' , $lists);
        } catch (\Exception $exception)
        {
            return JsonService::fail($exception->getMessage());
        }
    }


    public function get_table_list(Request $request , DatabaseLogic $database) : Json
    {
        try {
            $lists = $database->getTableList($request);
            return  JsonService::success('' , $lists);
        } catch (\Exception $e)
        {
            return JsonService::fail($e->getMessage());
        }
    }

    public function set_table_update(Request $request , JsonService $service) : Json
    {
        return $service -> handle(function(Request $request , DatabaseLogic $logic){
            return $logic->setField($request);
        });
    }


    public function migrations(Request $request , DatabaseLogic $database):Json
    {
        try {
            $lists = $database->migrationsList($request);
            return  JsonService::success('' , $lists);
        } catch (\Exception $e)
        {
            return JsonService::fail($e->getMessage());
        }
    }
}
